home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / foo2hp2600-wrapper < prev    next >
Encoding:
Text File  |  2009-03-27  |  17.4 KB  |  779 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2005-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2hp2600-wrapper.in,v 1.62 2008/12/07 00:45:18 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # hp2600 -
  27. #
  28.  
  29. PROGNAME="$0"
  30. BASENAME=`basename $PROGNAME`
  31. PREFIX=/usr
  32. SHARE=$PREFIX/share/foo2hp
  33. PATH=$PATH:/sw/bin:/opt/local/bin
  34.  
  35. #
  36. #    Log the command line, for debugging and problem reports
  37. #
  38. if [ -x /usr/bin/logger ]; then
  39.     logger -t "$BASENAME" -p lpr.info -- "$BASENAME $@" </dev/null
  40. fi
  41.  
  42. usage() {
  43.     cat <<EOF
  44. Usage:
  45.     $BASENAME [options] [ps-file]
  46.  
  47.     Foomatic printer wrapper for the foo2hp2600 printer driver.
  48.     This script reads a Postscript ps-file or standard input
  49.     and converts it to Zenographics ZjStream printer format.
  50.  
  51. Normal Options:
  52. -b bits           Bits per plane (1 or 2) [$BPP]
  53. -c                Print in color (else monochrome)
  54. -d duplex         Duplex code to send to printer [$DUPLEX]
  55.                     1=off, 2=longedge, 3=shortedge
  56. -m media          Media code to send to printer [$MEDIA]
  57.                     1=standard, 2=transparency, 3=glossy, 257=envelope,
  58.                     259=letterhead, 261=thickstock, 262=postcard, 263=labels
  59. -p paper          Paper code [$PAPER]
  60.                     1=letter, 5=legal, 7=executive, 9=A4, 11=A5, 13=B5
  61.                     20=env#10, 27=envDL 28=envC5 34=envB5 37=envMonarch
  62. -n copies         Number of copies [$COPIES]
  63. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  64. -s source         Source code to send to printer [$SOURCE]
  65.                     1=tray2, 2=tray3, 4=manual/tray1, 7=auto
  66.             Code numbers may vary with printer model.
  67. -t                Draft mode.  Every other pixel is white.
  68. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  69.                   Print with N-up (requires psutils)
  70. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  71.  
  72. Printer Tweaking Options:
  73. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  74. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  75. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  76.                   0=no, 1=Y, 2=X, 3=XY
  77. -P                Do not output START_PLANE codes.  May be needed by some
  78.                   monochrome-only printers.
  79. -X padlen         Add extra zero padding to the end of BID segments [16]
  80. -z model          Model: 0=HP CLJ 1600/2600n; 1=HP CLJ CP1215 [$MODEL]
  81.  
  82. Color Tweaking Options:
  83. -g gsopts         Additional options to pass to Ghostscript, such as
  84.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  85. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  86.                   adjust colors using the setcolorrendering PS operator.
  87.                   $SHARE/icm/ will be searched for profile.icm.
  88. -I intent         Select profile intent from ICM file [$INTENT]
  89.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  90. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  91.                   color correction using the setcolortransfer PS operator.
  92.  
  93. Debugging Options:
  94. -S plane          Output just a single color plane from a color print [all]
  95.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  96. -D lvl            Set Debug level [$DEBUG]
  97. -V                $VERSION
  98. EOF
  99.  
  100.     exit 1
  101. }
  102.  
  103. #
  104. #       Report an error and exit
  105. #
  106. error() {
  107.     echo "$BASENAME: $1" >&2
  108.     exit 1
  109. }
  110.  
  111. dbgcmd() {
  112.     if [ $DEBUG -ge 1 ]; then
  113.         echo "$@" >&2
  114.     fi
  115.     "$@"
  116. }
  117.  
  118. #
  119. # Portable version of 'which'
  120. #
  121. pathfind() {
  122.     if [ "$1" = -p ]; then
  123.     optp=1
  124.     shift
  125.     else
  126.     optp=0
  127.     fi
  128.     OLDIFS="$IFS"
  129.     IFS=:
  130.     for p in $PATH; do
  131.     if [ -x "$p/$*" ]; then
  132.         if [ $optp = 1 ]; then
  133.         echo "$p/$*"
  134.         fi
  135.         IFS="$OLDIFS"
  136.         return 0
  137.     fi
  138.     done
  139.     IFS="$OLDIFS"
  140.     return 1
  141. }
  142.  
  143. #
  144. # Returns true if $1 is 32-bit binary
  145. #
  146. is32() {
  147.     if pathfind file; then
  148.     path=`pathfind -p "$*"`
  149.     is32=`file -L "$path" | grep 32-bit` 
  150.     if [ "$is32" = "" ]; then
  151.         return 1
  152.     else
  153.         return 0
  154.     fi
  155.     else
  156.     return 1
  157.     fi
  158. }
  159.  
  160. #
  161. #    N-up-ify the job.  Requires psnup from psutils package
  162. #
  163. nup() {
  164.     case "$NUP" in
  165.     [2368]|1[0458])
  166.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  167.     ;;
  168.     [49]|1[26])
  169.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  170.     ;;
  171.     *)
  172.     error "Illegal call to nup()."
  173.     ;;
  174.     esac
  175. }
  176.  
  177. #
  178. #       Process the options
  179. #
  180.  
  181. # Try to use a local copy of GhostScript 8.54, if available.  Otherwise,
  182. # fallback to whatever the Linux distro has installed (usually 7.07)
  183. #
  184. # N.B. := operator used here, when :- would be better, because "ash"
  185. # doesn't have :-
  186. if gs.foo -v >/dev/null 2>&1; then
  187.         GSBIN=${GSBIN:-gs.foo}
  188. else
  189.         GSBIN=${GSBIN:-gs}
  190. fi
  191.  
  192. CMDLINE="$*"
  193. DEBUG=0
  194. DUPLEX=1
  195. BPP=1
  196. COLOR=
  197. COLORMODE=default
  198. MODEL=0
  199. QUALITY=1
  200. QUALITY=wts
  201.  
  202. MEDIA=1
  203. COPIES=1
  204. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  205. test "$PAPER" || PAPER=1
  206. RES=600x600
  207. SOURCE=7
  208. NUP=
  209. CLIP_UL=
  210. CLIP_LR=
  211. CLIP_LOG=
  212. BC=
  213. AIB=
  214. NOPLANES=
  215. COLOR2MONO=
  216. GAMMAFILE=default
  217. INTENT=0
  218. GSOPTS=
  219. EXTRAPAD=
  220. SAVETONER=
  221. NUP_ORIENT=
  222. GSDEV=-sDEVICE=pbmraw
  223. SEGFAULT=0
  224. # What mode to use if the user wants us to pick the "best" mode
  225. case `$GSBIN --version` in
  226. 7*)
  227.     DEFAULTCOLORMODE=10
  228.     ;;
  229. 8.1*)
  230.     # Buggy 8.14/8.15 in Ubuntu
  231.     DEFAULTCOLORMODE=10
  232.     if is32 $GSBIN; then
  233.         GAMMAFILE=km2430_2.icm
  234.     else
  235.         GAMMAFILE=hpclj2600n-0.icm
  236.     SEGFAULT=1
  237.     fi
  238.     QUALITY=1
  239.     ;;
  240. *)
  241.     DEFAULTCOLORMODE=10
  242.     ;;
  243. esac
  244.  
  245. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
  246. do
  247.     case $opt in
  248.     b)    BPP="$OPTARG";;
  249.     c)    COLOR=-c;;
  250.     d)    DUPLEX="$OPTARG";;
  251.     g)    GSOPTS="$GSOPTS $OPTARG";;
  252.     m)    MEDIA="$OPTARG";;
  253.     n)    COPIES="$OPTARG";;
  254.     p)    PAPER="$OPTARG";;
  255.     q)    QUALITY="$OPTARG";;
  256.     r)    RES="$OPTARG";;
  257.     s)    SOURCE="$OPTARG";;
  258.     t)    SAVETONER="-t";;
  259.     z)    MODEL="$OPTARG";;
  260.     l)    CLIP_LR="-l $OPTARG";;
  261.     u)    CLIP_UL="-u $OPTARG";;
  262.     L)    CLIP_LOG="-L $OPTARG";;
  263.     A)    AIB=-A;;
  264.     B)    BC=-B;;
  265.     C)    COLORMODE="$OPTARG";;
  266.     S)    COLOR2MONO="-S$OPTARG";;
  267.     D)    DEBUG="$OPTARG";;
  268.     G)    GAMMAFILE="$OPTARG";;
  269.     I)    INTENT="$OPTARG";;
  270.     P)    NOPLANES=-P;;
  271.     X)    EXTRAPAD="-X $OPTARG";;
  272.     [234689])    NUP="$opt";;
  273.     [57])    error "Can't find acceptable layout for $opt-up";;
  274.     1)    case "$OPTARG" in
  275.         [024568])    NUP="1$OPTARG";;
  276.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  277.         esac
  278.         ;;
  279.     o)    case "$OPTARG" in
  280.         l*)    NUP_ORIENT=-l;;
  281.         s*)    NUP_ORIENT=-r;;
  282.         p*|*)    NUP_ORIENT=;;
  283.         esac;;
  284.     V)    echo "$VERSION"; foo2hp -V; foo2zjs-pstops -V; exit 0;;
  285.     h|\?)
  286.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  287.             echo "Illegal command:"
  288.             echo "    $0 $CMDLINE"
  289.             echo
  290.         fi
  291.         usage;;
  292.     esac
  293. done
  294. shift `expr $OPTIND - 1`
  295.  
  296. #
  297. # If there is an argument left, take it as the file to print.
  298. # Else, the input comes from stdin.
  299. #
  300. if [ $# -ge 1 ]; then
  301.     if [ "$LPJOB" = "" ]; then
  302.     : # LPJOB="$1"
  303.     fi
  304.     exec < $1
  305. fi
  306.  
  307.  
  308. #
  309. #    Select the ghostscript device to use
  310. #
  311. case "$BPP" in
  312. 1)    if [ "" = "$COLOR" ]; then
  313.         GSDEV=-sDEVICE=pbmraw
  314.     else
  315.         GSDEV=-sDEVICE=bitcmyk
  316.     fi
  317.     case "$GAMMAFILE" in
  318.     default)
  319.         case "$MODEL" in
  320.         0)
  321.         if [ $SEGFAULT = 0 ]; then
  322.             GAMMAFILE=hpclj2600n-1.icm
  323.         else
  324.             GAMMAFILE=hpclj2600n-0.icm
  325.         fi
  326.         ;;
  327.         1)
  328.         GAMMAFILE=hp1215-argyll-0.icm
  329.         ;;
  330.         esac
  331.         ;;
  332.     none) GAMMAFILE=;;
  333.     esac
  334.     ;;
  335. 2)    if [ "" = "$COLOR" ];
  336.     then
  337.         # GSDEV=-sDEVICE=pgmraw
  338.         # error "2-bpp monochrome is not yet supported"
  339.         GSDEV="-sDEVICE=cups -dcupsColorSpace=3 -dcupsBitsPerColor=2"
  340.         GSDEV="$GSDEV -dcupsColorOrder=2"
  341.     else
  342.         GSDEV="-sDEVICE=cups -dcupsColorSpace=6 -dcupsBitsPerColor=2"
  343.         GSDEV="$GSDEV -dcupsColorOrder=2"
  344.     fi
  345.     if [ $GSBIN = "gs.foo" ]; then
  346.         GSBIN=gs
  347.     fi
  348.  
  349.     case "$GAMMAFILE" in
  350.     default) 
  351.         case "$MODEL" in
  352.         0)
  353.         if is32 $GSBIN; then
  354.             GAMMAFILE=km2430_2.icm
  355.             GAMMAFILE=hpclj2600n-1.icm
  356.         else
  357.             GAMMAFILE=
  358.         fi
  359.         ;;
  360.         1)
  361.         GAMMAFILE=hp1215-argyll-0.icm
  362.         ;;
  363.         esac
  364.         ;;
  365.     none) GAMMAFILE=;;
  366.     esac
  367.     ;;
  368. *)    error "Illegal number of bits per plane ($BPP)";;
  369. esac
  370.  
  371. #
  372. #    Validate model code
  373. #
  374. case "$MODEL" in
  375. 0|1)    ;;
  376. *)    error "Unknown model code $MODEL";;
  377. esac
  378.  
  379. #
  380. case "$QUALITY" in
  381. 0)
  382.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  383.     ;;
  384. 1)
  385.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  386.     ;;
  387. 2)
  388.     GSOPTS="-dMaxBitmap=500000000 $GSOPTS"
  389.     ;;
  390. wts)
  391.     GSOPTS="-dCOLORSCREEN -dMaxBitmap=500000000 $GSOPTS"
  392.     ;;
  393. esac
  394.  
  395. #
  396. #    Validate media code
  397. #
  398. case "$MEDIA" in
  399. 1|plain)    MEDIA=1;;
  400. 514|preprinted)    MEDIA=514;;
  401. 513|letterhead)    MEDIA=513;;
  402. 2|transparency)    MEDIA=2;;
  403. 515|prepunched)    MEDIA=515;;
  404. 265|labels)    MEDIA=265;;
  405. 260|bond)    MEDIA=260;;
  406. 516|recycled)    MEDIA=516;;
  407. 512|color)    MEDIA=512;;
  408. 276|tough)    MEDIA=276;;
  409. 267|envelope)    MEDIA=267;;
  410. 258|light)    MEDIA=258;;
  411. 262|heavy)    MEDIA=262;;
  412. 261|cardstock)    MEDIA=261;;
  413. 268|lightglossy)    MEDIA=268;;
  414. 269|glossy)    MEDIA=269;;
  415. 270|heavyglossy)    MEDIA=270;;
  416. 277|cover)    MEDIA=277;;
  417. 278|photo)    MEDIA=278;;
  418. [0-9]*)        ;;
  419. *)        error "Unknown media code $MEDIA";;
  420. esac
  421.  
  422. #
  423. #    Validate source (InputSlot) code
  424. #
  425. case "$SOURCE" in
  426. 1|tray2)    SOURCE=1;;
  427. 4|tray1)    SOURCE=4;;
  428. 7|auto)        SOURCE=7;;
  429. [0-9]*)        ;;
  430. *)        error "Unknown source code $SOURCE";;
  431. esac
  432.  
  433. #
  434. #    Validate Duplex code
  435. #
  436. case "$DUPLEX" in
  437. 1|off|none)    DUPLEX=1;;
  438. 2|long*)    DUPLEX=2;;
  439. 3|short*)    DUPLEX=3;;
  440. [0-9]*)        ;;
  441. *)        error "Unknown duplex code $DUPLEX";;
  442. esac
  443.  
  444. #
  445. #    Validate Resolution
  446. #
  447. case "$RES" in
  448. 600x600)    ;;
  449. 1200x600)    ;;
  450. 2400x600)    ;;
  451. *)        error "Illegal resolution $RES";;
  452. esac
  453.  
  454. #
  455. #    Figure out the paper dimensions in pixels/inch, and set the
  456. #    default clipping region.  Unfortunately, this is a trouble
  457. #    area for ZjStream printers.  Various versions of ZjS print
  458. #    engines react differently when asked to print into their
  459. #    unprintable regions.
  460. #
  461. set_clipping() {
  462.     ulx=$1; uly=$2
  463.     lrx=$3; lry=$4
  464.  
  465.     # Set clipping region if it isn't already set
  466.     if [ "$CLIP_UL" = "" ]; then
  467.     case "$RES" in
  468.     600x600)    ulx=`expr $ulx / 2`;;
  469.     2400x600)    ulx=`expr $ulx \* 2`;;
  470.     esac
  471.     CLIP_UL="-u ${ulx}x${uly}"
  472.     fi
  473.     if [ "$CLIP_LR" = "" ]; then
  474.     case "$RES" in
  475.     600x600)    lrx=`expr $lrx / 2`;;
  476.     2400x600)    lrx=`expr $lrx \* 2`;;
  477.     esac
  478.     CLIP_LR="-l ${lrx}x${lry}"
  479.     fi
  480. }
  481.  
  482. case "$PAPER" in
  483. Custom*)
  484.         case "$PAPER" in
  485.         Custom\.[0-9]*\x[0-9]*)
  486.             XDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/x.*//'`
  487.             YDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/.*x//'`
  488.             ;;
  489.         *)
  490.         #%%BeginFeature: *CustomPageSize True
  491.         #216
  492.         #360
  493.         #0
  494.         #0
  495.         #0
  496.         #pop pop pop pop pop
  497.  
  498.         #%%BeginFeature: *CustomPageSize True
  499.         #792.000000 612.000000 1 0.000000 0.000000
  500.         #pop pop pop pop pop
  501.  
  502.         if [ $DEBUG = 0 ]; then
  503.             TMPFILE=/tmp/cus$$
  504.         else
  505.             TMPFILE=/tmp/custom.ps
  506.         fi
  507.         cat >$TMPFILE
  508.         exec <$TMPFILE
  509.  
  510.         tmp=`head -n 10000 $TMPFILE \
  511.             | sed -n '/CustomPageSize/{n;p;n;p;}' \
  512.             | tr '\n' ' '`
  513.         case "$tmp" in
  514.         [0-9]*\ [0-9]*)
  515.             XDIM=`echo "$tmp" | sed 's/ .*//'`
  516.             YDIM=`echo "$tmp" | sed -e 's/^[^ ]* //' -e 's/ .*//'`
  517.             ;;
  518.         *)
  519.             if [ $DEBUG = 0 ]; then rm -f $TMPFILE; fi
  520.             error "Custom page size [XY]DIM != 1-99999"
  521.             ;;
  522.         esac
  523.         ;;
  524.         esac
  525.         XDIM=`dc -e "$XDIM 1200* 72/p"`
  526.         YDIM=`dc -e "$YDIM 600* 72/p"`
  527.         PAPER=1;        paper=letter;
  528.                 set_clipping 2 80     2 80
  529.         ;;
  530. 1|letter)    PAPER=1;    paper=letter;    XDIM="10200"; YDIM="6600"
  531.         set_clipping 172 80    172 80
  532.         ;;
  533. 5|legal)    PAPER=5;    paper=legal;     XDIM="10200"; YDIM="8400"
  534.         set_clipping 172 80    172 80
  535.         ;;
  536. 7|executive)    PAPER=7;    paper=executive; XDIM="8700";  YDIM="6300"
  537.         set_clipping 174 78    174 78
  538.         ;;
  539. 9|a4|A4)    PAPER=9;    paper=a4;        XDIM="9920";  YDIM="7016"
  540.         set_clipping 176 84    176 84
  541.         ;;
  542. 11|a5|A5)    PAPER=11;    paper=a5;        XDIM="6992";  YDIM="4960"
  543.         set_clipping 176 80    176 80
  544.         ;;
  545. 13|b5|B5|b5jis)    PAPER=13;    paper=b5;        XDIM="8598";  YDIM="6070"
  546.         set_clipping 172 83    171 83
  547.         ;;
  548. 20|"env#10")    PAPER=20;    paper=env10;     XDIM="4950";  YDIM="5700"
  549.         set_clipping 171 78    171 78
  550.         ;;
  551. 27|envDL)    PAPER=27;    paper=envDL;     XDIM="5200";  YDIM="5200"
  552.         set_clipping 176 84    176 84
  553.         ;;
  554. 28|envC5)    PAPER=28;    paper=envC5;     XDIM="7650";  YDIM="5408"
  555.         set_clipping 170 80    169 80
  556.         ;;
  557. 34|envB5)    PAPER=34;    paper=envB5;     XDIM="8316";  YDIM="5892"
  558.         set_clipping 174 74    174 74
  559.         ;;
  560. 37|envMonarch)    PAPER=37;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  561.         set_clipping 174 78    173 78
  562.         ;;
  563. *)        error "Unimplemented paper code $PAPER";;
  564. esac
  565. # e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
  566. PAPERSIZE="-sPAPERSIZE=$paper";
  567.  
  568. case "$RES" in
  569. 600x600)    XDIM=`expr $XDIM / 2`;;
  570. 1200x600)    ;;
  571. 2400x600)    XDIM=`expr $XDIM \* 2`;;
  572. esac
  573. DIM="${XDIM}x${YDIM}"
  574.  
  575. #
  576. # Filter thru psnup if N-up printing has been requested
  577. #
  578. case $NUP in
  579. [234689]|1[024568])    PREFILTER="nup";;
  580. *)            PREFILTER=cat;;
  581. esac
  582. if [ "$DEBUG" -ge 9 ]; then
  583.     PREFILTER="tee /tmp/$BASENAME.ps"
  584. fi
  585.  
  586. #
  587. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  588. #    then convert the ICC color profile to a Postscript CRD,
  589. #    then prepend it to the users job.  Select the intent
  590. #    using the -I option.
  591. #
  592.  
  593. create_crd() {
  594.     #
  595.     # Create a Postscript CRD
  596.     #
  597.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  598.     if [ -x $ICC2PS ]; then
  599.     case "$GAMMAFILE" in
  600.     none.icm | */none.icm)
  601.         ;;
  602.     *)
  603.         $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  604.         || error "Problem converting .ICM file to Postscript"
  605.         ;;
  606.     esac
  607.  
  608.     PSTOPS_OPTS="$PSTOPS_OPTS -c"
  609.     cat > $ICCTMP.usecie.ps <<-EOF
  610.         %!PS-Adobe-3.0
  611.         <</UseCIEColor true>>setpagedevice
  612.     EOF
  613.     if [ "$QUALITY" = wts ]; then
  614.         cat >> $ICCTMP.usecie.ps <<-EOF
  615.         << /UseWTS true >> setuserparams
  616.         <<
  617.             /AccurateScreens true
  618.             /HalftoneType 1
  619.             /HalftoneName (Round Dot Screen) cvn
  620.             /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
  621.             /Frequency 137
  622.             /Angle 37
  623.         >> sethalftone
  624.         EOF
  625.     fi
  626.     cat > $ICCTMP.selcrd.ps <<-EOF
  627.         /Current /ColorRendering findresource setcolorrendering
  628.     EOF
  629.     case "$GAMMAFILE" in
  630.     none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
  631.     *)    GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
  632.     esac
  633.     else
  634.     GAMMFILE=
  635.     fi
  636. }
  637.  
  638. if [ $DEBUG -gt 0 ]; then
  639.     ICCTMP=/tmp/icc
  640. else
  641.     ICCTMP=/tmp/icc$$
  642. fi
  643.  
  644. if [ "" = "$COLOR" ]; then
  645.     COLORMODE=
  646.     GAMMAFILE=
  647. else
  648.     case "$COLORMODE" in
  649.     default)    COLORMODE=$DEFAULTCOLORMODE;;
  650.     esac
  651. fi
  652.  
  653. CRDBASE="$PREFIX/share/foo2zjs/crd"
  654. PSFILES="$PREFIX/share/foo2hp/psfiles"
  655. case "$RES" in
  656.     600x600)    SCREEN=screen1200.ps;;
  657.     1200x600)    SCREEN=screen1200.ps;;
  658.     2400x600)    SCREEN=screen2400.ps;;
  659. esac
  660.  
  661. PSTOPS_OPTS="-n"
  662.  
  663. case "$COLORMODE" in
  664. 0|"")
  665.     # Monochrome
  666.     ;;
  667. 10|icm)
  668.     # Use old ICM method
  669.     AIB=-A
  670.     BC=-B
  671.     case "$GAMMAFILE" in
  672.     none.icm | */none.icm)
  673.     create_crd
  674.     ;;
  675.     *.icm|*.ICM|*.icc|*.ICC)
  676.     #
  677.     # Its really an .ICM file, not a gamma file.
  678.     #
  679.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  680.     #
  681.     if [ -r "$GAMMAFILE" ]; then
  682.         create_crd
  683.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  684.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  685.         create_crd
  686.     else
  687.         GAMMAFILE=
  688.     fi
  689.     ;;
  690.     esac
  691.     ;;
  692. *.crd)
  693.     GAMMAFILE="$CRDBASE/prolog.ps"
  694.     if [ -f $COLORMODE ]; then
  695.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  696.     elif [ -f $CRDBASE/$COLORMODE ]; then
  697.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  698.     else
  699.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  700.     fi
  701.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  702.     ;;
  703. *)
  704.     error "Unknown color method '$COLORMODE'"
  705.     ;;
  706. esac
  707.  
  708. if [ "$COLOR" != "" -a "$QUALITY" = wts ]; then
  709.     PSTOPS_OPTS="$PSTOPS_OPTS -w"
  710. fi
  711.  
  712. if [ "" != "$COLOR" ]; then
  713.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  714.     # Faster, but can't handle AllIsBlack or BlackClears
  715.     : #GSDEV=-sDEVICE=pksmraw
  716.     else
  717.     # Can't handle different size pages
  718.     : #GSDEV=-sDEVICE=bitcmyk
  719.     fi
  720. fi
  721.  
  722. #
  723. #    Figure out USERNAME
  724. #
  725. if [ "$LPUSER" != "" ]; then
  726.     USER="$LPUSER@$LPHOST"
  727. else
  728.     USER=""
  729. fi
  730.  
  731. #
  732. #    Main Program, just cobble together the pipeline and run it
  733. #
  734. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  735. #    (some versions?) of Ghostscript where Postscript's stdout gets
  736. #    intermingled with the printer drivers output, resulting in
  737. #    corrupted image data.
  738. #
  739. #    CUPS also does grief by adding its own PS code to the input file.
  740. #    We take care of that with the sed command.  Thus, Well Tempered
  741. #    Screening now works!
  742. #
  743. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  744.  
  745. foo2zjs-pstops $PSTOPS_OPTS | \
  746. $PREFILTER \
  747. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  748.     -sOutputFile="|cat 1>&3" $GAMMAFILE -_ >/dev/null 2>&1) 3>&1 \
  749. | foo2hp -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  750.         $COLOR -b$BPP $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  751.         -J "$LPJOB" -U "$USER" \
  752.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  753.  
  754. #
  755. #    Log the command line, for debugging and problem reports
  756. #
  757. if [ -x /usr/bin/logger ]; then
  758.     logger -t "$BASENAME" -p lpr.info -- \
  759.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS $GAMMAFILE"
  760.     logger -t "$BASENAME" -p lpr.info -- \
  761.     "foo2hp -r$RES -g$DIM -p$PAPER -m$MEDIA \
  762. -n$COPIES -d$DUPLEX -s$SOURCE $COLOR -b$BPP $CLIP_UL $CLIP_LR $CLIP_LOG \
  763. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  764. fi
  765.  
  766. #
  767. #    Remove cruft
  768. #
  769. if [ $DEBUG -eq 0 ]; then
  770.     for i in crd.ps log usecie.ps selcrd.ps
  771.     do
  772.     file="$ICCTMP.$i"
  773.     [ -f $file ] && rm -f $file
  774.     done
  775.     [ -f "$TMPFILE" ] && rm -f $TMPFILE
  776. fi
  777.  
  778. exit 0
  779.